
HAVE_DTRACE=0

# 32 bit
#MARCH=-m32 -msse2 -mfpmath=sse

# 64 bit
MARCH=-m64

OPT=-O2

# comment out this line to enable assertions at runtime
DEFS = -DNDEBUG

# uncommend this line to enable debug compilation
DEBUG ?= #empty by default

CC=gcc
CXX=g++
LD=$(CXX) $(OPT) $(MARCH)
WARN=-Wall
CWD=$(shell pwd)
CXXFLAGS=$(OPT) $(MARCH) $(DEBUG) $(WARN) $(DEFS) -fPIC
CCFLAGS=$(CXXFLAGS)


ARCH = $(shell uname)


ifeq ($(HAVE_DTRACE),1)
	DEFS += -DPBRT_PROBES_DTRACE
else
	DEFS += -DPBRT_PROBES_NONE
endif

ifeq ($(ARCH),Linux)
  LIBS += -lpthread
endif
ifeq ($(ARCH),OpenBSD)
  LIBS += -lpthread
endif
ifeq ($(ARCH),Darwin)
  LIBS += -lz
endif


######### TEST program ##########

TEST_OUT=out/test

LIB_OUT=out/libArgsFileParser.a

SRCS=$(wildcard src/*.cpp)

OBJS=$(patsubst %.cpp,objs/%.o,$(SRCS))

INCLUDES=-I./include -I../ThirdParty/rapidxml/1.13


###### Targets #########

all: test lib
	@echo Done

dirs:
	@mkdir -p out/
	@mkdir -p objs
	
test: dirs $(TEST_OUT)

lib: dirs $(LIB_OUT)


$(TEST_OUT): $(OBJS)
	@mkdir -p `dirname $@`
	$(CXX) $(CXXFLAGS) $(PROCEDURAL_LIBS) $(INCLUDES) $(OBJS) -o $@

$(LIB_OUT): objs/src/argsFileParser.o
	ar rcs $@ $<


objs/%.o: %.cpp
	@echo " Building object $@"
	@mkdir -p `dirname $@`
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ -c $<

	
clean:
	@echo Cleaning
	@rm -rf out objs
